<?php
namespace Admin\Model;
use Think\Model;
class GoalsModel extends Model {

  public function getChild($sector_id){
    $data = $this->select();
    return $this->getchildids($data,$sector_id);//刚开始出现错误是因为没有传值进去
  }

  public function getchildids($data,$sector_id){//以所要删除的数据的id作为父类id的数据全部给找出来
    static $arrid=array();//只创建一次，并且在这个作用于中不会被释放。数据会累加。
    $length1 = sizeof($arrid);
    $arrid[]=$sector_id;
    foreach ($data as $key => $value) {
       if ($value['parent_sector'] == $sector_id && $value['sector_id'] != $sector_id) {//子类
          $arrid[]=$value['sector_id'];
          $this->getchildids($data,$value['sector_id']);
       }
    }
    // return array_unique($arrid);//如果不用这个函数会出现重复，因为$arrid[]=$catedid因为放了两次id;
    $length2 = sizeof($arrid);
    $arr = array();
    for($i=$length1;$i<$length2;$i++){
    	$arr[$i]=$arrid[$i];         
    }
    return array_unique($arr);
  }
  //获取左侧信息栏
  public function getTd($arrSector,$dlsit_user){
    $arr = array('r'=>0,'d'=>NULL,'m'=>'OK');
    $where_user = array();
    $where_user['user_id'] = array('IN',$dlsit_user);
    $where_sector  = array();
    $where_sector['sector_id'] = array('IN',$arrSector);
    $dlist_sector = M() ->field('b.sector_id,b.sector_name as name')
              ->table('sector as b')
              ->where($where_sector)
              ->order('b.sector_id asc')
              ->select();
    $dlist_user = M() ->field('b.user_id,b.nickname as name')
              ->table('user as b')
              ->where($where_user)
              ->order('b.user_id asc')
              ->select();

    if($dlist_sector || $dlist_user){
      $arr['r'] = 1;
      $arr['d'] = $dlist_sector;
      $arr['m'] = $dlist_user;
    }
    return $arr;

  }

   

}